home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / Example Scripts / ResEditTest.vu < prev    next >
Encoding:
Text File  |  1998-06-04  |  16.5 KB  |  485 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        ResEditTest.vu
  3. #
  4. #    Contains:    A ResEdit test script that creates a window for each of the predefined resource types.
  5. #                If you have a file called "vu-wants-1-of-each" on the topmost volume, this script
  6. #                will delete it and recreate it.  This name is kept in a string called gResFileName
  7. #                and can be changed if desired.
  8. #
  9. #                This script does quite a bit so it takes a while to execute.  If you would rather
  10. #                have it create some number of resource type windows less than the total, modify the 
  11. #                value of numberOfResourcesToMake. The following statement will create the 
  12. #                first 15 resource types:                    
  13. #                    numberOfResourcesToMake := 15;
  14. #                The variable numberOfResourcesToMake is used to pass a second parameter to 
  15. #                CreateOneOfEachType() which indicates the number of resource types you'd 
  16. #                like created. 
  17. #
  18. #                This script demonstrates how to use the scroll command to scroll through a 
  19. #                scrolling list of items.  Run it and watch what it does with scrolling.
  20. #
  21. #    Libraries:    "UtilityTasks.vulib"
  22. #
  23. #    Prerequisites: 
  24. #                Be sure the UtilityTasks.vulib library is available.
  25. #                The Finder must be the active app.(preferably the only app. running).
  26. #                If the target is running under a 6.0.x system, then:
  27. #                    The ResEdit app must be in the root directory as the first file listed 
  28. #                    (view by name and rename to start its name with 'aa' for example). 
  29. #                    Either this window should be open and no other;
  30. #                    or the volume icon selected and no windows open. 
  31. #                If the target is running under a 7.0.x system, then:
  32. #                    The ResEdit app must be the first occurance of ResEdit which Finder's 
  33. #                    Find command will select. This is best accomplished by putting it in the  
  34. #                    frontmost window and removing any other files with 'ResEdit' in it's name.
  35. #
  36. #    Written by:    Jay Jessen and Rick Violet
  37. #
  38. #    Copyright:    © 1990-1992 by Apple Computer, Inc., all rights reserved.
  39. #
  40. #    Change History:
  41. #
  42. #         7/21/92    DGG            Made main body into script.
  43. #         7/7/92        DGG            Revamped variable names.
  44. #         6/18/92    DGG            Added handling for Sys6 "replace" dialog.
  45. #         1/9/91        Rick        Moved some Tasks to "UtilityTasksLib.vu"
  46. #         1/4/91        naga        Modified the header comments 
  47. #         1/2/91        Rick        Updated Jay's version so that this script will run against both
  48. #                                ResEdit v1.2 and ResEdit v2.1 (under system 6.0x and system 7.0).
  49. #                                In the process defined some new tasks modified some old tasks and
  50. #                                task names
  51. #         6/7/89        Jay            Created from an old version (optimized scrolling actions)
  52. #
  53. #    To Do:
  54. #
  55.  
  56. Libraries "UtilityTasks.vulib";
  57.  
  58. (************************************************************************************
  59. * Task SetScreenDependents()
  60. ************************************************************************************)
  61. task SetScreenDependents() 
  62. begin
  63.     # Where to drag resource windows to get them out of the way
  64.     global Wind_x := 250;    # hardwired for now
  65.     global Wind_y := 20;    # hardwired for now
  66. end;
  67.  
  68. (************************************************************************************
  69. * Task ClearFile(fileToClear,checkSelection := true)
  70. *    clears a file from Volume window, 
  71. *    if checkSelection is false it'll clear the current selection ( For ResEdit 1.2 )
  72. ************************************************************************************)
  73. task ClearFile(fileToClear,checkSelection := true) 
  74. begin    
  75.     global gVolumeName;
  76.     
  77.     if (not match[window t:gVolumeName o:1]!)
  78.         select [window t:gVolumeName]!;
  79.     if (checkSelection) 
  80.     begin
  81.         type k:{ "v" };
  82.         foundIt := false;
  83.         while (not foundIt) 
  84.         begin
  85.             UseKeyboardEquivalent("o");
  86.             if (match [staticText t:/The file≈has no resource fork≈Do you wish≈it ∂?/
  87.                                     w:[window o:1 s:dialog]]!) 
  88.             begin
  89.                 select [button t:'Cancel']!;
  90.                 type k:{ downarrowKey };
  91.             end;
  92.             else 
  93.             begin
  94.                 if (((match [window o:1]!).t) = fileToClear) 
  95.                 begin
  96.                     foundIt := true;
  97.                     close [window o:1]!;
  98.                 end;
  99.                 else 
  100.                 begin
  101.                     close [window o:1]!;
  102.                     type k:{ downarrowKey };
  103.                 end;
  104.             end;
  105.         end;
  106.     end;
  107.     select [menuItem t:'Clear' m:'Edit']!;
  108.     if (match [button t:'OK']! and match[button t:'Cancel']!) 
  109.         select [button t:'OK'];
  110. end;
  111.  
  112. (************************************************************************************
  113. * Task CreateResourceFile(gResFileName)
  114. *    Creates a resource file of name gResFileName. 
  115. *    Replaces any previously existing file of that name. ( For ResEdit 1.2 )
  116. ************************************************************************************)
  117. task CreateResourceFile(gResFileName) 
  118. begin
  119.     global gVolumeName;
  120.     
  121.     if(not match[window t:gVolumeName o:1]!)
  122.         select [window t:gVolumeName]!;
  123.     select [menuItem title:'New' m:'File']!;
  124.     type k:{ gResFileName };
  125.     select [button title:'OK']!;
  126.     if(match[button t:'OK' w:[window o:1]]!) 
  127.     begin 
  128.         select [button t:'OK']!;
  129.         select [button t:'Cancel']!;
  130.         ClearFile(gResFileName);
  131.         select [menuItem title:'New' m:'File']!;
  132.         type k:{ gResFileName };
  133.         select [button title:'OK']!;
  134.     end;
  135. end;
  136.  
  137. (************************************************************************************
  138. * Task CreateResourceFile2(gResFileName)
  139. *    Creates a resource file of name gResFileName. 
  140. *    Replaces any previously existing file of that name. ( For ResEdit 2.1 )
  141. ************************************************************************************)
  142. task CreateResourceFile2(gResFileName) begin
  143.  
  144.     global gVolumeName;
  145.     
  146.     wait(2);
  147.     
  148.     if( not match [window] )
  149.         select [menuItem title:/New≈/ m:'File']!;
  150.     else if (match [button  t:"New" ]! and match [button t:"Open"]!)
  151.         select [ button t:"New" ];
  152.  
  153.     wait(2);
  154.     
  155.     type k:{ gResFileName };
  156.     select [button title:'New']!;
  157.  
  158.     wait(2);
  159.     if (match [staticText t:?dialogText w:[window o:1 s:dialog]]!)
  160.     begin
  161.         if (dialogText ~= /Replace≈/)
  162.         begin
  163.             if (match [button t:'Replace'])
  164.                 select [button t:'Replace']!;
  165.             else if (match [button t:'Yes'])
  166.                 select [button t:'Yes']!;
  167.         end;
  168.     end;
  169. end;
  170.  
  171. (************************************************************************************
  172. * Task SetScrollBarGlobals() 
  173. *    set global values for scroll bar in "Select New Type" dialog    ( For ResEdit 1.2 )
  174. ************************************************************************************)
  175. task SetScrollBarGlobals() 
  176. begin
  177.  
  178.     global gScrollbarLeft,gScrollbarTop,gScrollbarRight,gScrollbarBottom;
  179.     global gPreviousScrollerSetting;
  180.  
  181.     select [menuItem title:/New≈/ m:'File']!;
  182.     
  183.     # get the "select new type" dialog's bounding rect and put it in windowRect
  184.     match [window o:1 r:?windowRect]!;
  185.     
  186.     # get the scroll bar's current setting and rectangle (in local coords)
  187.     currentScroller := match [scrollBar    windowOwner:[window o:1]
  188.                                 s:?controlValue r:?scrollerRect]!;
  189.     
  190.     # ~~~~~ compute scroll bar rect in global coordinates (8 compensate for the dialog border pixels)
  191.     gScrollbarLeft := scrollerRect[1];
  192.     gScrollbarTop := scrollerRect[2];
  193.     gScrollbarRight := scrollerRect[3];
  194.     gScrollbarBottom := scrollerRect[4];
  195.     
  196.     if(controlValue[1] = controlValue[2])
  197.         global gDoneScrolling := true;
  198.     else
  199.         gPreviousScrollerSetting := controlValue;
  200. end;
  201.  
  202. (************************************************************************************
  203. * Task SetScrollBarGlobals2()
  204. *    set global values for scroll bar in "Select New Type" dialog ( For ResEdit 2.1 )
  205. ************************************************************************************)
  206. task SetScrollBarGlobals2() 
  207. begin
  208.     global gScrollbarLeft,gScrollbarTop,gScrollbarRight,gScrollbarBottom;
  209.     global gPreviousScrollerSetting;
  210.  
  211.     select [menuItem title:/Create New Resource/ m:'Resource']!;
  212.     
  213.     # get the "select new type" dialog's bounding rect and put it in windowRect
  214.     match [window ord:1 rect:?windowRect]!;
  215.     
  216.     # get the scroll bar's current setting and rectangle (in local coords)
  217.     currentScroller := match [scrollBar    windowOwner:[window o:1]
  218.                                     s:?controlValue r:?scrollerRect]!;
  219.     
  220.     # ~~~~~ compute scroll bar rect in global coordinates (8 compensate for the dialog border pixels)
  221.     gScrollbarLeft := scrollerRect[1];
  222.     gScrollbarTop := scrollerRect[2];
  223.     gScrollbarRight := scrollerRect[3];
  224.     gScrollbarBottom := scrollerRect[4];
  225.     
  226.     if(controlValue[1] = controlValue[2])
  227.         global gDoneScrolling := true;
  228.     else
  229.         gPreviousScrollerSetting := controlValue;
  230. end;
  231.  
  232. (************************************************************************************
  233. * Task PositionResTypeWindow()
  234. *    Position the resource type window, away from the volume window ( For ResEdit 1.2 )
  235. ************************************************************************************)
  236. task PositionResTypeWindow() 
  237. begin
  238.     drag [window ord:1] a:{ global Wind_x,global Wind_y };
  239.     Wind_x := Wind_x + 1;
  240.     Wind_y := Wind_y + 2;
  241. end;
  242.  
  243. (************************************************************************************
  244. * Task SelectNextType()
  245. *    scrolls to the next resource type in the "Select New Type" dialog
  246. ************************************************************************************)
  247. task SelectNextType() 
  248. begin
  249.     global gPreviousScrollerSetting,clicksForCurrentValue;
  250.     global gDoneScrolling;
  251.     global listItemHeight;
  252.     global gScrollbarLeft,gScrollbarTop,gScrollbarRight,gScrollbarBottom;
  253.     global gNonTopItemSelection;
  254.     
  255.     scroll [scrollBar w:[window o:1]] a: gPreviousScrollerSetting;
  256.     if(gDoneScrolling) begin # ~~ only need to select the remaining visible items (no more scrolling)
  257.         move a:{ gScrollbarLeft - 10,
  258.                     gScrollbarTop + ((gNonTopItemSelection - 1) * listItemHeight) + 5 };
  259.         gNonTopItemSelection := gNonTopItemSelection + 1;
  260.     end;
  261.     else 
  262.     begin 
  263.         move a:{ gScrollbarRight - 5,gScrollbarBottom - 5 };
  264.         click;
  265.         match [scrollBar w:[window ord:1] setting:?controlValue]!;
  266.         if(controlValue[1] = gPreviousScrollerSetting[1])
  267.         begin # ~~~~~~~ scroll value hasn't changed
  268.             clicksForCurrentValue := clicksForCurrentValue + 1;
  269.             for i := 1 to clicksForCurrentValue click;
  270.         end;
  271.         else
  272.             clicksForCurrentValue := 0;
  273.         move a:{ gScrollbarLeft - 10,gScrollbarTop + 5 };
  274.     end;
  275.     click;# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make the new selection
  276.     if (not gDoneScrolling) begin
  277.         match [scrollBar w:[window ord:1] setting:?controlValue]!;
  278.         gPreviousScrollerSetting := controlValue;
  279.         if (controlValue[1] = controlValue[2]) begin
  280.             gDoneScrolling := true;
  281.             listItemHeight := 
  282.                 (gScrollbarBottom - gScrollbarTop) / 7;# ~~~~~~~~~~~~~~~ 7 is the number of visible types
  283.             gNonTopItemSelection := 2;# ~~~~~~~~~~~~~~~~~~~~ now used to select remaining visible items 
  284.         end;
  285.     end;
  286. end;
  287.  
  288. (************************************************************************************
  289. * Task CheckForAlertOrPositionWindow()
  290. *    checks for an alert and if one isn't there positions the window, 
  291. *    else it logs the alert and dismisses it
  292. ************************************************************************************)
  293. task CheckForAlertOrPositionWindow() 
  294. begin
  295.     if(match[button w:[window ord:1 style:dialog] t:'OK']!) 
  296.     begin
  297.         text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
  298.         println "Dismissing dialog that came up after resource type selection -- static text messages follow:";
  299.         for each m in text_messages println " ∂t",m.t;
  300.         select [button t:'OK'];
  301.     end;
  302.     else
  303.         PositionResTypeWindow();
  304. end;
  305.  
  306. (************************************************************************************
  307. * Task CheckForAlertOrPositionWindow2() 
  308. *    checks for an alert and if one isn't there positions the window, 
  309. *    else it logs the alert and dismisses it. There is an exception for FOND resource 
  310. *    ( For ResEdit 2.1 )
  311. ************************************************************************************)
  312. task CheckForAlertOrPositionWindow2() 
  313. begin
  314.  
  315.     if(match[ button w:[window o:1 s:dialog ] t:'OK' ]!) 
  316.         if( match[ statictext t:/≈Adding a font≈/ ]! )
  317.             Type k:{returnKey,"Chicago",tabKey,"12",returnKey};
  318.         else                
  319.             begin
  320.             text_messages := collect[staticText w:[window ord:1 style:dialog]]!;
  321.             println "Dismissing dialog that came up after resource type selection -- static text messages follow:";
  322.             for each m in text_messages println " ∂t",m.t;
  323.             select [button t:'OK'];
  324.             end;
  325.         
  326.     if( match [window t:/≈ID =≈/]! )
  327.         if ( match [window o:1 c:true]! )  
  328.             close [window o:1];
  329.         else if( match [menuItem title:'Close' m:'File' e:1 ]! )
  330.             select [menuItem title:'Close' m:'File']!;
  331.  
  332.     if( match [window t:?tText ] and tText <> global gResFileName )
  333.         PositionResTypeWindow();
  334.     
  335. end;
  336.  
  337. (************************************************************************************
  338. * Task CreateOneOfEachType( someOfEach := 0)
  339. *    This task creates one of each resource type if someOfEach is zero.
  340. *    It will create the first ten resource types if someOfEach is 10. etc. ( ResEdit 1.2 )
  341. ************************************************************************************)  
  342. task CreateOneOfEachType( someOfEach := 0) 
  343. begin
  344.     global gScrollbarLeft,gScrollbarTop;
  345.     global gResFileName;
  346.  
  347.     SetScrollBarGlobals();
  348.     move a:{gScrollbarLeft - 10, gScrollbarTop + 5 };
  349.     click;
  350.     select [button t:'OK']!;
  351.     CheckForAlertOrPositionWindow();
  352.     creationsCount := 1;
  353.  
  354.     while ((global gNonTopItemSelection <> 8) and  
  355.             ((not someOfEach) or (creationsCount <> someOfEach))) 
  356.     begin
  357.             if(not match[window t:gResFileName o:1]!) select [window t:gResFileName]!;
  358.             select [menuItem title:'New' m:'File']!;
  359.             SelectNextType();
  360.             creationsCount := creationsCount + 1;
  361.             select [button t:'OK']!;
  362.             CheckForAlertOrPositionWindow();
  363.     end;
  364. end;
  365.  
  366. (**************************************************************************************************** 
  367. * Task CreateOneOfEachType2( someOfEach )
  368. *    This task creates one of each resource type if someOfEach is zero.
  369. *    It will create the first ten resource types if someOfEach is 10. etc.
  370. ****************************************************************************************************)  
  371. task CreateOneOfEachType2( someOfEach := 0) 
  372. begin
  373.     global gScrollbarLeft,gScrollbarTop;
  374.     global gResFileName;
  375.     
  376.     SetScrollBarGlobals2();
  377.     move a:{ gScrollbarLeft - 10, gScrollbarTop + 5 };
  378.     click;
  379.     select [button t:'OK']!;
  380.     CheckForAlertOrPositionWindow2();
  381.     creationsCount := 1;
  382.  
  383.     while ((global gNonTopItemSelection <> 8) and  
  384.             ((not someOfEach) or (creationsCount <> someOfEach))) 
  385.     begin
  386.         select [window t:global gResFileName];
  387.         wait(1);
  388.         select [menuItem title:'Create New Resource' m:'Resource']!;
  389.         wait(2);
  390.         SelectNextType();
  391.         creationsCount := creationsCount + 1;
  392.         wait(1);
  393.         select [button t:'OK']!;
  394.         CheckForAlertOrPositionWindow2();
  395.     end;
  396. end;
  397.  
  398. (**************************************************************************************************** 
  399. * Script ResEditMain(numberOfResourcesToMake)
  400. *    The script parameter numberOfResourcesToMake determines how many resources should
  401. *    be made.  Setting it to a value of 0 will cause ResEditTest to create one of each
  402. *    type of resource.
  403. ****************************************************************************************************)  
  404. script ResEditMain(numberOfResourcesToMake := 0)
  405. begin
  406.     match [target t:?targetName];
  407.  
  408.     global gResEdit2;
  409.     global gVolumeName;
  410.  
  411.     global gSystem7 := RunningSystemSeven();
  412.     if gSystem7 
  413.         println targetName, " Running System 7";
  414.     else 
  415.         println targetName, " Not Running System 7";
  416.  
  417.     if gSystem7
  418.         launchOk := LaunchAppInSystem7("ResEdit");
  419.     else
  420.         launchOk := LaunchAppInSystem6("ResEdit");
  421.     if not launchOk
  422.         GracefulExit("ResEdit failed to launch");
  423.  
  424.     wait(2);
  425.     if (match [menu t:"Resource"])
  426.     begin
  427.         gResEdit2 := true;
  428.         println targetName, " Running ResEdit2.1";
  429.     end;
  430.     else
  431.     begin
  432.         gResEdit2 := false;
  433.         println targetName, " Running ResEdit1.2";
  434.     end;
  435.  
  436.     # when gNonTopItemSelection = 7, 
  437.     # all types have been created (7 is the number of visible items)
  438.     gNonTopItemSelection := 0;
  439.     gDoneScrolling := false;
  440.     clicksForCurrentValue := 0;
  441.                                             ##    Set this as you like:
  442.     gResFileName := "vu-wants-1-of-each";    #    File name to use
  443.                                             
  444.     SetScreenDependents();
  445.  
  446.     if gResEdit2
  447.     begin        
  448.         if ( match[ window t:"" o:1]! and not match[ button ] )    # Splash Screen?
  449.             Select [ Window o:1 ];
  450.     
  451.         CreateResourceFile2(gResFileName);
  452.         CreateOneOfEachType2( numberOfResourcesToMake );
  453.     
  454.         verifString := "window titles follow for verification";
  455.         println "∂n",verifString;
  456.         for i := 1 to (card verifString) 
  457.             print "=";
  458.         println;
  459.         
  460.         for each w in collect[window] 
  461.             println w.title;     # ~~~~~~~~ to verify that all the windows were created
  462.     
  463.         select [menuItem t:'quit'];
  464.         select [button t:"No"];
  465.     end;
  466.     else
  467.     begin
  468.         match [window o:1 t:?gVolumeName]!;
  469.         CreateResourceFile(gResFileName);
  470.         CreateOneOfEachType( numberOfResourcesToMake );
  471.         
  472.         verifString := "window titles follow for verification";
  473.         println "∂n",verifString;
  474.         for i := 1 to card(verifString) 
  475.             print "=";
  476.         println;
  477.         
  478.         for each w in collect[window] 
  479.             println w.title;     # ~~~~~~~~ to verify that all the windows were created
  480.     
  481.         ClearFile(gResFileName,true);
  482.         select [menuItem t:'quit'];
  483.     end;
  484. end;
  485.